package com.ucode.model.hrm.form;

import cn.hutool.core.util.ObjUtil;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.hibernate.validator.constraints.Range;

import javax.validation.constraints.AssertTrue;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.time.LocalDate;
import java.util.List;

@Schema(description = "人力资源管理系统 - 员工合同创建Form")
@Data
@EqualsAndHashCode
@ToString(callSuper = true)
public class HrmEmployeeContractCreateForm {

    @Schema(description = "员工集合", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotEmpty(message = "员工集合不能为空")
    private List<Long> employeeIds;

    @Schema(description = "合同模板", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotNull(message = "合同模板不能为空")
    private Long contractTplId;

    @Schema(description = "签约公司", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotNull(message = "签约公司不能为空")
    private Long signCompanyId;

    @Schema(description = "合同类型:1 入职合同 2 续签合同 3 离职协议", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotNull(message = "合同类型不能为空")
    @Range(min = 1, max = 3, message = "合同类型范围：1 入职合同 2 续签合同 3 离职协议")
    private Integer contractType;

    @Schema(description = "合同结束时间", requiredMode = Schema.RequiredMode.AUTO)
    private LocalDate endDate;

    @AssertTrue(message = "合同结束时间不能为空")
    public boolean isEndDateCheck() {
        if(!ObjUtil.equals(contractType,1) && ObjUtil.isNull(this.endDate)){
            return false;
        }
        return true;
    }

}
